<template>
    <div>
        <h3>人员列表</h3>
        <h3 style="color:red">Count组件的求和数是:{{sum}}</h3>
        <input type="text" v-model="name" placeholder="请输入名字">
        <button @click="add">添加</button>
        <button @click="addPersonServer">随机添加</button>
        <ul>
            <li v-for="person in personList" :key="person.id">
                {{person.name}}
            </li>
        </ul>
    </div>
</template>

<script>
    import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
    import {nanoid} from 'nanoid'

    export default {
        name:'Preson',
        computed:{
            personList(){
                return this.$store.state.personAbout.personList
            },
            //...mapState('personAbout',['personList']),
            sum(){
                return this.$store.state.countAbout.sum
            }
        },
        data() {
            return {
                name:'',
            }
        },
        methods: {
            add(){
                const person = {id:nanoid(),name:this.name}
                this.name=''
                this.$store.commit('personAbout/ADD_PERSON',person)
                //...mapMutations('countAbout',{increment:'ADD',decrement:'DECREMENT'}),
            },
            addPersonServer(){
                this.$store.dispatch('personAbout/addPersonServer')

            }
        },
    }
</script>

<style>

</style>